package com.yeyks.controller.activity;

import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.activity.dal.domain.ActivityDrawRecordNew;
import com.yeyks.activity.service.ActivityDrawRecordNewService;
import com.yeyks.annotation.NeedToken;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.base.PageResult;
import com.yeyks.common.em.accountinfo.AccountInfoTypeEnum;
import com.yeyks.common.param.PageParam;
import com.yeyks.common.result.activity.*;
import com.yeyks.commonReference.append.activity.ActivityDoubleDanService;
import com.yeyks.web.AccountUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "v3.8活动统计")
@RestController
@Slf4j
@RequestMapping("/activity/stat")
public class ActivityStatisticalController {

    @Autowired
    private ActivityDrawRecordNewService activityDrawRecordNewService;
    @Autowired
    private ActivityDoubleDanService activityDoubleDanService;

    @ApiOperation(value = "v3.8活动总统计", response = ActivityStatTotalResult.class)
    @PostMapping(value = "/total")
    public AjaxResponseBody<ActivityStatTotalResult> total() {
        ActivityStatTotalResult result = activityDoubleDanService.statTotal();
        return AjaxResponseBody.success(result);
    }

    @ApiOperation(value = "v3.8各节点红包领取统计", response = ActivityStatRedResult.class)
    @PostMapping(value = "/red/total")
    public AjaxResponseBody<List<ActivityStatRedResult>> redTotal() {
        List<ActivityStatRedResult> activityStatRedResults = activityDoubleDanService.redTotal();
        return AjaxResponseBody.success(activityStatRedResults);
    }

    @ApiOperation(value = "v3.8活动点击量统计", response = ActivityStatClickResult.class)
    @PostMapping(value = "/click/total")
    public AjaxResponseBody<List<ActivityStatClickResult>> clickTotal() {
        List<ActivityStatClickResult> activityStatClickResults = activityDoubleDanService.clickTotal();
        return AjaxResponseBody.success(activityStatClickResults);
    }

    @ApiOperation(value = "v3.8活动转发人数统计", response = ActivityStatForwardUserResult.class)
    @PostMapping(value = "/forward/user/total")
    public AjaxResponseBody<List<ActivityStatForwardUserResult>> forwardUserTotal() {
        List<ActivityStatForwardUserResult> activityStatForwardUserResults = activityDoubleDanService.forwardUserTotal();
        return AjaxResponseBody.success(activityStatForwardUserResults);
    }

    @ApiOperation(value = "v3.8活动转发次数统计", response = ActivityStatForwardTimeResult.class)
    @PostMapping(value = "/forward/time/total")
    public AjaxResponseBody<List<ActivityStatForwardTimeResult>> forwardTimeTotal() {
        List<ActivityStatForwardTimeResult> activityStatForwardTimeResults = activityDoubleDanService.forwardTimeTotal();
        return AjaxResponseBody.success(activityStatForwardTimeResults);
    }
    @NeedToken
    @ApiOperation(value = "v3.8活动中奖列表", notes = "总公司权限", response = ActivityDrawRecordNew.class)
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public AjaxResponseBody<PageResult<ActivityDrawRecordNew>> list(PageParam page) {
        AccountInfo loginUser = AccountUtils.getLoginUser();
        Arguments.isTrue(!AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType()), "您无权查看");
        PageResult<ActivityDrawRecordNew> pageResult = activityDrawRecordNewService.myList(page);
        return AjaxResponseBody.success(pageResult);
    }

}
